var order = ['red', 'yellow', 'blue', 'green']
var app = getApp();
var it;
Page({
  data: {
    toView: 'red',
    scrollTop: 100,
    width:'50%',
    swiperdat: [],
    books1:['1','2'],
    books2:['4','5'],
    tabbar: {},
    userInfo:{},
    address:{},
      bow:2,
      keyword:''
  },
  toinfo:function(e){
      var uid = e.currentTarget.dataset.uid;
  	wx.navigateTo({
  		url:'/pages/find/bookinfo2?uid='+uid
  	})
  }, 
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    app.editTabBar();
    app.getUserInfo();
    var that = this;
    this.setData({
      userInfo:app.globalData.userInfo

    })

    // console.log(getCurrentPages());
  },
  onShow:function(e){
    var that = this;
    if(undefined == app.globalData.address.longitude || parseFloat(app.globalData.address.longitude) <=0){
        it = setInterval(function(){
            if(app.globalData.address.longitude>0){
                that.setData({
                    address:app.globalData.address
                })
                that.getDataList();
                clearInterval(it);
            }
        },200)
    }else{
        that.setData({
            address:app.globalData.address
        })
    }

      this.getDataList();
  },
    //修改搜索的值
    searchword:function(e){
        var that = this;
        that.setData({
            keyword:e.detail.value
        })
        // console.log(that.data.keyword)
    },
    //搜索按钮
    searchevent:function(e){
      // console.log('search')
      this.getDataList();
    },
    bindconfirm:function(e){
        var that = this;
        that.setData({
            keyword:e.detail.value
        })
        this.getDataList();
    },
    toCity:function(e){
      // console.log(123)
      wx.navigateTo({
        url:'/pages/wx-index-list/city'
      })
  },
    totest:function(e){
      console.log(123)
    },
    //获取用户及发布的书籍
    getDataList:function(e){
        var that = this;
        // console.log('123123'+ app.globalData.address.city)
        wx.request({
            url: app.data.server+'/index.php/Tongcheng/Book/getBookList',
            data:{bow:that.data.bow,keyword:that.data.keyword,city:app.globalData.address.city,longitude:app.globalData.address.longitude,latitude:app.globalData.address.latitude},
            header: {'content-type': 'application/x-www-form-urlencoded'},
            method:'POST',
            dataType:'json',
            success:function(d){
                // console.log('123'+JSON.stringify(d.data));
                that.setData({
                    swiperdat:d.data
                })
            }
        })
    },
    toGuangGao:function(e){
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/find/guanggao?id='+id
      })
    },
    clearKeyWord:function(e){
      console.log('clearKeyWord')
        this.setData({
            keyword:''
        })
        this.getDataList();
    }
})